//
//  YHUIToolkit.m
//  YiHuBaiYing
//
//  Created by FranklinPhill on 15/12/14.
//  Copyright © 2015年 Fire. All rights reserved.
//

#import "SHUIToolkit.h"
#import "TKAlertCenter.h"
#import "TopLoadingView.h"

@implementation SHUIToolkit

+ (void)alertMessage:(NSString *)message {
    if (message.length <= 0) {
        return;
    }
    [[TKAlertCenter defaultCenter] postAlertWithMessage:message];
}

+ (void)showLoadingInView:(UIView *)view withTitle:(NSString *)title {
    [TopLoadingView showInView:view title:title delegate:nil obscure:YES useClose:NO];
}

+ (void)showCouldCancelLoadingInView:(UIView *)view withTitle:(NSString *)title delegate:(id)delegate {
    [TopLoadingView showInView:view title:title delegate:delegate obscure:YES useClose:YES];
}

+ (void)hideLoadingMessageInView:(UIView *)view {
    [TopLoadingView hide];
}

+ (UIColor *)colorWithHexString:(NSString *)stringToConvert {
    NSString *cString = [[stringToConvert stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] uppercaseString];
    
    if ([cString length] < 6) {
        return [UIColor whiteColor];
    }
    if ([cString hasPrefix:@"#"]) {
        cString = [cString substringFromIndex:1];
    }
    if ([cString length] != 6) {
        return [UIColor whiteColor];
    }
    
    NSRange range;
    range.location = 0;
    range.length = 2;
    NSString *rString = [cString substringWithRange:range];
    
    range.location = 2;
    NSString *gString = [cString substringWithRange:range];
    
    range.location = 4;
    NSString *bString = [cString substringWithRange:range];
    
    unsigned int r, g, b;
    [[NSScanner scannerWithString:rString] scanHexInt:&r];
    [[NSScanner scannerWithString:gString] scanHexInt:&g];
    [[NSScanner scannerWithString:bString] scanHexInt:&b];
    
    return RGBColor(r, g, b);
}

@end
